package com.zbkj.front.controller;

import com.zbkj.common.model.user.UserBankCard;
import com.zbkj.common.request.UserBankCardBindRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.token.FrontTokenComponent;
import com.zbkj.service.user.UserBankCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 用户银行卡表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/front/user/bank/card")
@Api(tags = "用户银行卡表") //配合swagger使用
@RequiredArgsConstructor
public class UserBankCardController {

    private final UserBankCardService userBankCardService;
    private final FrontTokenComponent frontTokenComponent;

    @ApiOperation(value = "查询自己的银行卡")
    @GetMapping("/self")
    public CommonResult<UserBankCard> self() {
        Integer userId = frontTokenComponent.getUserId();
        UserBankCard userBankCard = userBankCardService.getByUid(userId);
        return CommonResult.success(userBankCard);
    }

    @ApiOperation(value = "绑定银行卡")
    @PostMapping("/bind")
    public CommonResult<Void> self(@Validated @RequestBody UserBankCardBindRequest request) {
        Integer userId = frontTokenComponent.getUserId();
        userBankCardService.userBindBankCard(request, userId);
        return CommonResult.success();
    }
}



